<template>
  <div class="main">
    <div class="title">{{ companyInfo.companyName }}</div>
    <div class="JBQK">
      <div class="tit">
        <img src="@/assets/image/jbqk.png" alt="" />
        <div>基本情况</div>
      </div>
      <div class="msg">
        <div>户号:{{ companyInfo.houseNumber || "-" }}</div>
        <div>
          合同期限
          {{
            companyInfo.contractDate
              ? companyInfo.contractDate.split(";")[0]
              : "-"
          }}
          至
          {{
            companyInfo.contractDate
              ? companyInfo.contractDate.split(";")[1]
              : "-"
          }}
        </div>
        <div>
          <i
            v-for="i in companyInfo.starLevel || 5"
            :key="i"
            class="el-icon-star-on"
          ></i>
        </div>
      </div>
      <div class="box">
        <div class="mbox">
          <img src="@/assets/image/byq.png" alt="" />
          <div class="mbox-m">
            <div style="margin-bottom:5px">变压器</div>
            <div class="text">
              <span class="num">{{ companyInfo.transformerNumber }}</span> (台)
            </div>
          </div>
        </div>
        <div class="mbox">
          <img src="@/assets/image/rl.png" alt="" />
          <div class="mbox-m">
            <div style="margin-bottom:5px">容量</div>
            <div class="text">
              <span class="num">{{ companyInfo.transformerNumber }}</span> (kVA)
            </div>
          </div>
        </div>
        <div class="mbox">
          <img src="@/assets/image/fh.png" alt="" />
          <div class="mbox-m">
            <div style="margin-bottom:5px">本月最大负荷</div>
            <div class="text">
              <span class="num">{{ companyInfo.transformerNumber }}</span> (kW)
            </div>
          </div>
        </div>
        <div class="mbox">
          <img src="@/assets/image/fh.png" alt="" />
          <div class="mbox-m">
            <div style="margin-bottom:5px">最大负载率</div>
            <div class="text">
              <span class="num">{{ companyInfo.transformerNumber }}</span> (%)
            </div>
          </div>
        </div>
      </div>
      <div class="msg2">
        <div class="msg2-m">
          <div class="left">
            基本电费缴费方式：{{
              companyInfo.electricityFeeType == "01"
                ? "按运行容量"
                : "按需求容量"
            }}
          </div>
          <div class="right">
            合理<el-switch
              style="margin: 0 20px"
              :width="80"
              :value="!companyInfo.electricityFeeTyperReasonableFlag"
              disabled
            >
            </el-switch
            >有待优化
          </div>
        </div>
        <div class="msg2-m">
          <div class="left">
            月度平均功率因数：{{ companyInfo.averageLoadFactor }}
          </div>
          <div class="right">
            合理<el-switch
              style="margin: 0 20px"
              :width="80"
              :value="!companyInfo.averageLoadFactorReasonableFlag"
              disabled
            >
            </el-switch
            >有待优化
          </div>
        </div>
      </div>
    </div>
    <div class="YNQS">
      <div class="tit">
        <img src="@/assets/image/ynqs.png" alt="" />
        <div>用能趋势</div>
      </div>
      <div class="top">
        <div>
          本月截止目前用电量 {{ companyInfo.monthLoad }} kWh，本年累计用电量
          {{ companyInfo.yearLoad }} kWh
        </div>
        <div style="color: #4095e5">
          {{ companyInfo.lastElcReport?.split(";")[1] }}
        </div>
      </div>
      <div id="ynqs" style="width: 100%; height: 200px"></div>
    </div>
    <div class="YWQK">
      <div class="tit">
        <img src="@/assets/image/ywqk.png" alt="" />
        <div>运维情况</div>
      </div>
      <div class="finbox">
        <div class="left">
          <div class="ppp" style="display: flex; margin-bottom: 10px">
            本年度已执行巡视:{{ companyInfo.inspectionsExecutedTimes }}次
            <div class="progress">
              <div
                :style="{
                  width: XSCS + '%',
                  height: '100%',
                  'background-color': '#81b337',
                }"
              ></div>
              <div
                :style="{
                  width: 100 - XSCS + '%',
                  height: '100%',
                  'background-color': '#4095e5',
                }"
              ></div>
            </div>
            还剩次数:{{ companyInfo.pendingInspectionsTimes }}次
          </div>
          <p>
            最近一次巡视报告:<a href="#">{{
              companyInfo.lastInspectionReport?.split(";")[1]
            }}</a>
          </p>
          <p>
            本年度发现缺陷 <span>{{ companyInfo.defectsNumber }}个</span>
          </p>
          <p>
            已处理缺陷 <span>{{ companyInfo.defectsHandledNumber }}个</span>
          </p>
          <p>
            未处理缺陷 <span>{{ companyInfo.defectsUnHandledNumber }}个</span>
          </p>
        </div>
        <div id="right" style="width: 300px; height: 230px" />
      </div>
    </div>
    <div class="SPJK">
      <div class="tit">
        <img src="@/assets/image/spjk.png" alt="" />
        <div>视频监控</div>
      </div>
      <div class="jk">
        <div class="jk-box" v-for="video in videoList" :key="video.id">
          <MyVideo v-if="video.id" :video="video" />
        </div>
      </div>
      <el-empty
        class="empty"
        v-if="videoList?.length == 0"
        description="暂无监控"
      ></el-empty>
    </div>
    <div class="KHPJ">
      <div class="khpj">客户评价</div>
      <div class="service">
        <div class="service-item">
          <div class="text">服务人员</div>
          <div>
            <img src="@/assets/image/评价.png" v-for="i in 5" :key="i" />
          </div>
        </div>
        <div class="service-item">
          <div class="text">服务态度</div>
          <div>
            <img src="@/assets/image/评价.png" v-for="i in 5" :key="i" />
          </div>
        </div>
        <div class="service-item">
          <div class="text">服务效果</div>
          <div>
            <img src="@/assets/image/评价.png" v-for="i in 5" :key="i" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import * as echarts from 'echarts'
import MyVideo from './MyVideo'
import { getCameraListApi } from '@/api/surveillance'
export default {
  namr: 'CompanyInfo',
  props: ['companyInfo'],
  components: { MyVideo },
  data () {
    return {
      Chart1: null,
      Chart2: null,
      options1: null,
      options2: null,
      videoList: []
    }
  },
  created () {
    this.getCameraList()
  },
  mounted () {
    this.myChart1()
    this.myChart2()
  },
  computed: {
    month () {
      return this.companyInfo.trend?.map((item) => item.month + '月')
    },
    JDL () {
      return this.companyInfo.trend?.map((item) => item.epowerFee1)
    },
    FDL () {
      return this.companyInfo.trend?.map((item) => item.epowerFee2)
    },
    PDL () {
      return this.companyInfo.trend?.map((item) => item.epowerFee3)
    },
    GDL () {
      return this.companyInfo.trend?.map((item) => item.epowerFee4)
    },
    XSCS () {
      const inspectionsExecutedTimes = parseInt(
        this.companyInfo.inspectionsExecutedTimes
      )
      const pendingInspectionsTimes = parseInt(
        this.companyInfo.pendingInspectionsTimes
      )
      return (
        inspectionsExecutedTimes /
          (inspectionsExecutedTimes + pendingInspectionsTimes) || 0
      )
    }
  },
  methods: {
    myChart1 () {
      this.Chart1 = echarts.init(document.getElementById('ynqs'))
      this.options1 = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            data: this.month
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: [
          {
            name: '尖费率',
            type: 'bar',
            barWidth: 30,
            stack: 'Ad',
            emphasis: {
              focus: 'series'
            },
            data: this.JDL,
            itemStyle: {
              color: '#ff6666'
            }
          },
          {
            name: '峰费率',
            type: 'bar',
            stack: 'Ad',
            emphasis: {
              focus: 'series'
            },
            data: this.FDL,
            itemStyle: {
              color: '#5996ff'
            }
          },
          {
            name: '平费率',
            type: 'bar',
            stack: 'Ad',
            emphasis: {
              focus: 'series'
            },
            data: this.PDL,
            itemStyle: {
              color: '#18f2ce'
            }
          },
          {
            name: '谷费率',
            type: 'bar',
            stack: 'Ad',
            emphasis: {
              focus: 'series'
            },
            data: this.GDL,
            itemStyle: {
              color: '#ffbe4c'
            }
          }
        ]
      }
      this.Chart1.setOption(this.options1)
    },
    myChart2 () {
      this.Chart2 = echarts.init(document.getElementById('right'))
      this.options2 = {
        tooltip: {
          trigger: 'item'
        },
        legend: {
          orient: 'vertical',
          right: 10,
          top: 20,
          bottom: 20
        },
        series: [
          {
            type: 'pie',
            radius: '50%',
            label: {
              show: false,
              position: 'center'
            },
            itemStyle: {
              borderRadius: 10,
              borderColor: '#fff',
              borderWidth: 2
            },
            data: [
              {
                value: this.companyInfo.defectsHandledNumber || 0,
                name: '已处理'
              },
              {
                value: this.companyInfo.defectsUnHandledNumber || 0,
                name: '未处理'
              }
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      }
      this.Chart2.setOption(this.options2)
    },
    async getCameraList () {
      const res = await getCameraListApi()
      console.log(res)
      this.videoList = (res.data.list.find(
        (item) => item.orgName == this.companyInfo.companyName
      )?.cameraList) || []
      console.log(this.videoList)
    }
  }
}
</script>

<style lang="scss" scoped>
.main {
  padding: 0 20px 20px;
  .title {
    font-size: 20px;
  }
  .JBQK {
    padding-right: 100px;
    padding-bottom: 10px;
    padding-top: 10px;
    border-bottom: 2px solid rgba(187, 187, 187, 1);
    .tit {
      display: flex;
      font-weight: bold;
      margin-bottom: 10px;
      img {
        margin-right: 10px;
      }
    }
    .msg {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 10px;
      .el-icon-star-on {
        color: red;
        font-size: 27px;
      }
    }
    .box {
      display: flex;
      justify-content: space-between;
      margin-bottom: 20px;
      .mbox {
        display: flex;
        width: 190px;
        height: 80px;
        padding: 10px 10px;
        border: 1px solid rgba(187, 187, 187, 1);
        img {
          margin-right: 20px;
        }
        .mbox-m {
          .text {
            .num {
              font-size: 25px;
              color: #000;
            }
          }
        }
      }
    }
    .msg2 {
      padding-right: 180px;
      .msg2-m {
        display: flex;
        justify-content: space-between;
        margin-bottom: 10px;
      }
    }
  }
  .YNQS {
    padding-bottom: 10px;
    padding-top: 10px;
    border-bottom: 2px solid rgba(187, 187, 187, 1);
    .tit {
      display: flex;
      font-weight: bold;
      margin-bottom: 10px;
      img {
        margin-right: 10px;
      }
    }
    .top {
      display: flex;
      justify-content: space-between;
      padding: 10px 100px 0 60px;
    }
  }
  .YWQK {
    width: 100%;
    height: 250px;
    padding-bottom: 10px;
    padding-top: 10px;
    border-bottom: 2px solid rgba(187, 187, 187, 1);
    .tit {
      display: flex;
      font-weight: bold;
      margin-bottom: 10px;
      img {
        margin-right: 10px;
      }
    }
  }
}
.finbox {
  position: relative;
  .left {
    p {
      margin-bottom: 5px;
    }
    .ppp {
      .progress {
        display: flex;
        width: 655px !important;
        height: 20px;
        margin-left: 20px;
        margin-right: 20px;
      }
    }
  }
  #right {
    position: absolute;
    top: 20px;
    right: 60px;
  }
}
.SPJK {
  padding-bottom: 10px;
  padding-top: 10px;
  .tit {
    display: flex;
    font-weight: bold;
    margin-bottom: 10px;
    img {
      margin-right: 10px;
    }
  }
  .jk {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    padding: 0 40px;
    .jk-box {
      width: 40%;
      height: 200px;
      margin-bottom: 20px;
      margin-right: 30px;
    }
  }
  .empty {
    text-align: center;
  }
}
.KHPJ {
  padding: 10px;
  .khpj {
    font-weight: bold;
    margin-bottom: 10px;
  }
  .service {
    padding-left: 30px;
    .service-item {
      display: flex;
      align-items: center;
      margin-bottom: 10px;
      .text {
        margin-right: 10px;
      }
      img {
        margin-right: 15px;
      }
    }
  }
}
</style>
